// 查找页面上的所有图片元素

const images = document.querySelectorAll('img');
	images.forEach((item)=>{
		const downloadBtn = document.createElement('button')
		downloadBtn.innerHTML = '下载图片'
		downloadBtn.style.position = 'absolute'
		downloadBtn.style.top = '5px'
		downloadBtn.style.right = '5px'
		downloadBtn.style.color = '#fff'
		downloadBtn.style.background = '#333'
		downloadBtn.style.padding = '5rpx 10rpx'
		downloadBtn.style.zIndex = '99999'
		downloadBtn.addEventListener('click', (event) => {
			event.stopPropagation();
			event.preventDefault();
			const imageUrl = item.src;
			chrome.runtime.sendMessage({ action: 'downloadImage', url: imageUrl });
		});
		
		item.parentNode.style.position = 'relative';
		item.parentNode.appendChild(downloadBtn);
		
	})